package Main;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


import Component.MyForm;
import Global.GlobalGameOption;
import Global.ResourceManager;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;

/**
 *
 * @author Huy
 */
public class GameStateEnd extends GameState {

	int t = 0;
	Sound music ;

	public GameStateEnd(Game _game, boolean win) {
		super(_game);
		
		String str;
		
		if (win) {
			str = "ingame/winbackground";
			music = GlobalGameOption.MUSIC.getMusic("win");
		} else {
			str = "ingame/defeatedbackground";
			music = GlobalGameOption.MUSIC.getMusic("defeated");
		}
		music.start();
		t=0;
		form = new MyForm(ResourceManager.getImage(str), game.getWidth(), game.getHeight());
	}

	@Override
	public void update(float d) {
		t++;
	}

	@Override
	public void keyReleased(KeyEvent e) {
		super.keyReleased(e);
		if (t > 50) {
			music.stop();
			game.gameState = new GameMenuState(game);
		}
	}

	@Override
	public void mouseReleased(MouseEvent e) {
		super.mouseReleased(e);
		if (t > 50) {
			music.stop();
			game.gameState = new GameMenuState(game);
		}
	}
}
